#!/usr/bin/env python
#coding=utf-8
#find lines of file2 which time in file1
import time,datetime

file1='2012.02.18 00:05:00|2012.02.18 00:10:59'
file2='''00:00:00|00:04:59
00:05:00|00:09:59
00:10:00|00:14:59
00:15:00|00:19:59
00:20:00|00:24:59
00:25:00|00:29:59
00:30:00|00:34:59
00:35:00|00:39:59
00:40:00|00:44:59
00:45:00|00:49:59
00:50:00|00:54:59
00:55:00|00:59:59
01:00:00|01:04:59
23:35:00|23:39:59
23:40:00|23:44:59
23:45:00|23:49:59
23:50:00|23:54:59
23:55:00|23:59:59'''

def buildtime(strtime,timeformat):
    strtime1,strtime2=strtime.split('|')
    time1=tuple(time.strptime(strtime1,timeformat))[0:6]
    time2=tuple(time.strptime(strtime2,timeformat))[0:6]
    t1=datetime.time(time1[-3],time1[-2],time1[-1])
    t2=datetime.time(time2[-3],time2[-2],time2[-1])
    return t1,t2

def main(f1,f2):
    timeformat='%Y.%m.%d %H:%M:%S'
    time1,time2=buildtime(f1,timeformat)    
    print f1
    print '='*50
    
    timeformat='%H:%M:%S'
    for line in f2.split('\n'):
        t1,t2=buildtime(line,timeformat)
        if time1<=t1<=time2:
            print line
        
if __name__ == '__main__':
    main(file1,file2)
